import { createPage } from '@mpxjs/core';
import {AlbumBrief, Song} from "../../services/types";
import {DetailOfCustomEvent, WrapWidthUndefined} from "../../utils/typies";
import {similarAlbums, similarSongs} from "../../services/song.service";
// similarSongs, similarAlbums
interface PlaySongVo {
  data: {
    song: WrapWidthUndefined<Song>;
    similarSongs: Song[];
    similarAlbums: AlbumBrief[];
  }
}

createPage<PlaySongVo['data']>({
  data: {
    song: undefined,
    similarSongs: [],
    similarAlbums: [],
  },
  onLoad () {
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.once('songBriefFromList', (song: Song) => {
      console.log('song', song);
      if (song) {
        this.song = song;
        Promise
          .all([similarSongs(song.songid), similarAlbums(song.songid)])
          .then(([songs, albums]) => {
            this.similarSongs = songs;
            console.log('similarSongs', this.similarSongs);
            this.similarAlbums = albums;
          });
      }
    });
  },
  toList(event: DetailOfCustomEvent<AlbumBrief>): void {
    wx.navigateTo({
      url: '/pages/song-list/index',
      success({ eventChannel }) {
        eventChannel.emit('albumBriefFromRecommend', event.detail);
      }
    });
  }
});

